define(['app',
    "resources/FileuploadResource",
    "directives/attachs/AttachsDisplay"
], function (app) {
	
	var deps = ["FileuploadResource"];
	
	function fileDisplayFun(FileuploadResource){
		return {
			replace : true,
			templateUrl : "views/common/fileupload/FileDisplay.html",
			scope : {
				idConfig : "=idConfig",
                removeAble : "=?"
			},
			link : function($scope, element, attrs){
				$scope.$watch(attrs.idConfig, function(){
					if ($scope.idConfig != null) {
						var idType = $scope.idConfig["idType"],
							id = $scope.idConfig["id"];
						if (idType == "taskId") {
							FileuploadResource.queryTaskAttachs(id).success(function(data) {
			        			// 拆分显示附件列表
		                		$scope.attachs = data;
			    			});
						}
					}
				});
				$scope.$on("event.upload.display", function(event, tasksyns){
	                // 拆分显示附件列表
                    $scope.attachs = tasksyns;
				});

                //
				$scope.$on("event.attach.remove", function(event, data){
                    if ($scope.idConfig != null) {
                        var idType = $scope.idConfig["idType"],
                            id = $scope.idConfig["id"];
                        FileuploadResource.delAttachs(idType, id, data.attachsId).success(function(result) {
                            if (result === "true" && data.callback) {
                                data.callback();
                            }
                        });
                    }
				});

			}
		};
	}

	fileDisplayFun.$inject = deps;
	
    app.lazy.directive('fcFileDisplay', fileDisplayFun);
});